package com.haorui.lygyd.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * 创建人: 陈刚
 * 日期: 2017/9/24
 * 时间: 22:51
 * 功能：请进行修改
 */
@Configuration
@EnableScheduling
public class ScheduleConfig {
    @Autowired
    @Qualifier("druidDataSource")
    DataSource dataSource;
    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        bean.setDataSource(dataSource);
        Properties quartzProperties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("quartz.properties"));
        bean.setQuartzProperties(quartzProperties);
        bean.setSchedulerName("RenrenScheduler");
        bean.setApplicationContextSchedulerContextKey("applicationContextKey");
        bean.setOverwriteExistingJobs(true);
        bean.setAutoStartup(true);
        bean.setStartupDelay(5);
        return bean;
    }
}
